package com.kunbo.cn.app.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.app.entity.Driver;
import com.kunbo.cn.app.service.DriverService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.ResultBean;

@RestController
@RequestMapping("/driver")
public class DriverController {
	
	@Autowired
	private DriverService dao;
	
	
	/**
	 * 新增司机
	 * @param number
	 * @param name
	 * @param idcrad
	 * @param contact_number
	 * @param drivers_license
	 * @return
	 */
	@PostMapping("/saveDriver")
	public ResultBean<Boolean> saveDriver(
			@RequestParam("unit")String unit,
			@RequestParam("uuid")String uuid,
			@RequestParam("create_user_id")String create_user_id,
			@RequestParam("number")String number,
			@RequestParam("name")String name,
			@RequestParam("idcrad")String idcrad,
			@RequestParam("contact_number")String contact_number,
			@RequestParam("drivers_license")String drivers_license
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", dao.saveDriver(number, name, idcrad, contact_number, drivers_license,uuid,create_user_id,unit));
	}
	
	/**
	 * 修改司机信息
	 * @param id
	 * @param number
	 * @param name
	 * @param idcrad
	 * @param contact_number
	 * @param drivers_license
	 * @return
	 */
	@PostMapping("/updateDriver")
	public ResultBean<Boolean> updateDriver(
			@RequestParam("id")Integer id,
			@RequestParam("number")String number,
			@RequestParam("name")String name,
			@RequestParam("idcrad")String idcrad,
			@RequestParam("contact_number")String contact_number,
			@RequestParam("drivers_license")String drivers_license
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", dao.updateDriver(id,number, name, idcrad, contact_number, drivers_license));
	}
	
	/**
	 * 获取司机个人信息
	 * @param id
	 * @return
	 */
	@PostMapping("selById")
	public ResultBean<Driver> selById(
			@RequestParam("id")Integer id
			){
		ResultBean<Driver> result = new ResultBean<Driver>();
		return BuildBean.buildResult(result, "success", "error", dao.selById(id));
	}
	
	
	
	/**
	 * 获取司机手机号（表单）
	 * @param id
	 * @return
	 */
	@PostMapping("/selPhoneById")
	public String selPhoneById(
			@RequestParam("id")Integer id
			){
		return dao.selPhoneById(id);
	}
	
	
	
	/**
	 * 删除司机
	 * @param id
	 * @return
	 */
	@PostMapping("/delById")
	public ResultBean<Boolean> delById(
			@RequestParam("id")Integer id
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", dao.delById(id));
	}
	
	
	/**
	 * 司机列表
	 * @return
	 */
	@PostMapping("/selDriver")
	public ResultBean<List<Map<String,Object>>> selDriver(
			@RequestParam("wayBillUnit")Integer wayBillUnit
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", dao.selDriver(wayBillUnit));
	}
	
	
	/**
	 * 根据司机名查询
	 * @param name
	 * @return
	 */
	@PostMapping("/selDriverByName")
	public ResultBean<List<Map<String,Object>>> selDriverByName(
			@RequestParam("wayBillUnit")Integer wayBillUnit,
			@RequestParam("name")String name
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", dao.selDriverByName(name,wayBillUnit));
	}
	
	/**
	 * 
	 * <p>Title: getAllDriver</p>
	 * <p>Description:获取所有空闲的司机并能够根据身份证号模糊查询 </p>
	 * @param idcrad
	 * @return
	 */
	@PostMapping("/getDriversByIdCard")
	public CommonResult getAllDriver(
			@RequestParam(value="idcrad",required=false)String idcrad
			){
		return new CommonResult(true,"获取成功",dao.getAllDrivers(idcrad));
	}
	
	
	
	
	
	
	

}
